package cn.xzqwjw.taskmanager.service.impl;

import cn.xzqwjw.taskmanager.domain.pojo.LogLogin;
import cn.xzqwjw.taskmanager.repository.LogLoginMapper;
import cn.xzqwjw.taskmanager.service.LogLoginService;
import cn.xzqwjw.taskmanager.utils.ConvertUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

/**
 * @author rush
 */
@Service("LogLoginService")
@Transactional(rollbackFor = Exception.class)
public class LogLoginServiceImpl extends ServiceImpl<LogLoginMapper, LogLogin>
    implements LogLoginService {

  @Override
  public Integer countTotalLoginNumber(Integer idAdmin) {
    QueryWrapper<LogLogin> wrapper = new QueryWrapper<>();
    wrapper.eq("id_admin", idAdmin);
    return ConvertUtil.lng2int(count(wrapper));
  }

  @Override
  public Map<String, Object> getLastLoginInfoByIdAdmin(Integer idAdmin) {
    QueryWrapper<LogLogin> wrapper = new QueryWrapper<>();
    wrapper.eq("id_admin", idAdmin)
        .orderByDesc("id")
        .last("limit 1");
    return getMap(wrapper);
  }

}
